#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<sys/wait.h>
#define MAXARGS 20
#define ARGLEN 80

int main(){
        while(1){
                printf(">");
                char argbuf[ARGLEN * MAXARGS];
                char *arglist[MAXARGS + 1];
                int index = 0;
                fgets(argbuf,ARGLEN,stdin);
                arglist[index++] = strtok(argbuf," \n");
                while((arglist[index++] = strtok(NULL," \n")));
                arglist[index-1] = 0;
                int newpid;
                if((newpid =fork()) == -1)
                        perror("fork");

                //child code
                else if (newpid == 0)
                        execvp(*arglist,arglist);

                //parent code
                else
                {
                        int wait_rv;
                        wait_rv = wait(NULL);
                        printf("done waiting for %d.returned:%d\n",newpid,wait_rv);
                }

}}
